def f(n):
    for i in range(2, n):
        if n % i == 0:  return False
    return True


nums = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']
left = []
right = []
s = input()
a = s.split()
if len(a) != 3:
    print("Wrong input")
elif (a[0] in nums) and (a[1] in nums) and (a[2] in nums):
    b = ''
    for x in a:
        b += str(nums.index(x))
    b = int(b)
    for c in range(2, b):
        if f(c):
            left.append(c)
    for k in range(b, 1015):
        if f(k):
            right.append(k)
    if (b - max(left)) <= (min(right) - b):
        print(max(left))
    elif (b - max(left)) > (min(right) - b):
        print(min(right))
else:
    print("Wrong input")